﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using CaptureImageMergeSys.Utility;
using System.Xml.Serialization;
using CaptureImageMergeSys.ConfigModel;
using System.IO;

namespace CaptureImageMergeSys
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ConfigReader objReader = new ConfigReader(@"../../ConfigFile/CapturedImageMergerSysSetting.xml");
            float fValue = 0;
            objReader.ParseFloatElementValue(@"TestFloatReader", ref fValue);

            //test loading xml by serialization.
            ConfigTest.LoadConfig();

            Application.Run(new MainPanel());
        }
    }

    class ConfigTest
    {
        public static void LoadConfig()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(AppConfig));
            FileStream fs = null;
            string strFilePath = @"../../ConfigFile/CapturedImageMergerSysSetting.xml";
            object objTemp = null;
            try
            {
                fs = File.Open(strFilePath, FileMode.Open, FileAccess.Read);

                objTemp = serializer.Deserialize(fs);
            }
            catch (Exception ex)
            {
                Console.WriteLine("IO error or Deserialize error.");
                Console.WriteLine(ex.Message);
            }

            AppConfig config = objTemp as AppConfig;

            if (config == null)
            {
                Console.WriteLine("Config error.");
                return;
            }

            Console.WriteLine("Application Info:" + config.GlobalConfig.ApplicationName + ":" + config.GlobalConfig.SystemVersion);
            Console.WriteLine("First Image Info:" + config.ImageMergeInfo.FirstImageInfo.Location + ";" + config.ImageMergeInfo.FirstImageInfo.Position);
            Console.WriteLine("Second Image Info:" + config.ImageMergeInfo.SecondImageInfo.Location + ";" + config.ImageMergeInfo.SecondImageInfo.Position);
            Console.WriteLine("Load configuration success.");
        }
    }
}
